<template>
  <div style="width: 350px">
    <el-form ref="formRef" :model="form" label-width="70px" :rules="rules">
      <el-form-item label="原密码 " prop="oldpwd">
        <el-input v-model="form.oldpwd" type="password" />
      </el-form-item>
      <el-form-item label="新密码 " prop="newpwd">
        <el-input v-model="form.newpwd" type="password" />
      </el-form-item>
      <el-form-item label="确认密码" prop="confirmpwd">
        <el-input v-model="form.confirmpwd" type="password" />
      </el-form-item>
    </el-form>
    <el-button type="primary" @click="handleClick" style="margin-left: 175px"
      >提交</el-button
    >
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { doctorModifyPwd } from '@/api/modifyPwd'
import { SHA256 } from '@/api/sha256'
const form = ref({
  oldpwd: '',
  newpwd: '',
  confirmpwd: ''
})
const account = localStorage.getItem('Doctoraccount')
const rules = ref({
  oldpwd: [{ required: true, message: '请输入原密码', trigger: 'blur' }],
  newpwd: [{ required: true, message: '请输入新密码', trigger: 'blur' }],
  confirmpwd: [{ required: true, message: '请确认新密码', trigger: 'blur' }]
})
const handleClick = async () => {
  if (form.value.newpwd === form.value.confirmpwd) {
    const res = await doctorModifyPwd({
      account,
      oldpassword: SHA256(form.value.oldpwd),
      newpassword: SHA256(form.value.newpwd)
    })
    alert(res.data.msg)
  } else {
    alert('密码不一致')
  }
}
</script>

<style></style>